import scala.collection.mutable

object CommonUtils {

  def countWords(text:String) ={
    val counts = mutable.Map.empty[String,Int]
    for(rawWord <- text.split("[ !,.]+")){
      val word = rawWord.toLowerCase
      val oldCount =
        //判断是否包含，包含取出Value，不包含Value为0
        if(counts.contains(rawWord))  counts(word) else 0
      counts +=(word -> (oldCount +1))
    }
    counts
  }

  def main(args: Array[String]): Unit = {
    println(countWords("elements,and and a[fast .length operation. ALinearSeq provides"))
  }

}
